<template>
	<view>
		<que-nav :loreName="loreName" :taskName="loreTaskName" @backUp="backUp"></que-nav>
		<view class="studyWrap">
			<study-step @goStepStudy="goStepStudy"></study-step>
		</view>
	</view>
</template>

<script>
	import QueNav from '../queList/components/QueNav'
	import StudyStep from './components/StudyStep'
	import { getStepQuestionData } from '@/api/zhuxue'
	import zhuxueUtils from '@/common/zhuxueUtils.js'
	export default {
		components:{
			QueNav,
			StudyStep
		},
		data() { 
			return {
				studyLogId:0,
				nextLoreIdArray:'',
				loreName:'',
				loreTaskName:'',
				currSubId:0,
				loreId:0,
				currentLoreId:0
			}
		},
		onLoad(options){
			this.studyLogId = options.studyLogId;
			this.nextLoreIdArray = options.nextLoreIdArray;
			this.loreName = options.loreName;
			this.loreTaskName = options.loreTaskName;
			this.currSubId = options.currSubId;
			this.loreId = options.loreId;
			this.getStepQuestionData();
		},
		onUnload(){
			uni.removeStorageSync('stepField');
			uni.removeStorageSync('studyQueList');
		},
		methods: {
			getStepQuestionData(){
				//var stepField = uni.getStorageSync('stepField');
				var field = { account:uni.getStorageSync('token'),loreTypeName:'practice',studyLogId:this.studyLogId,nextLoreIdArray:this.nextLoreIdArray,loreTaskName:this.loreTaskName };
				let contentStr = this.crypto.encrypt(JSON.stringify( field )); 
				getStepQuestionData({content:contentStr}).then(res=>{
					//console.log(res) 
					this.currentLoreId = res.data.datas.currentLoreId;
					var lqList = res.data.datas.sourceDetail;
					var reg = new RegExp("Module/", "g");
					for(let i in lqList){
						if(lqList[i].lqSub.indexOf('Module/') != -1){
							lqList[i].lqSub = lqList[i].lqSub.replace(reg, this.zhuXueServer + '/Module/');
						}
						lqList[i].answerOptionArray = zhuxueUtils.radomAnswerArray( zhuxueUtils.assignToArray(lqList[i].answerA,lqList[i].answerB,lqList[i].answerC,lqList[i].answerD,lqList[i].answerE,lqList[i].answerF) );
						lqList[i].optIndex = -1;//单选题 判断题 下标
						lqList[i].currAns = '';
						lqList[i].result = -1;//0->错 1对 每道题提交后记录当前回答是否正确
						lqList[i].completeStatus = 0; 
						if(lqList[i].lqType == '单选题' ||　lqList[i].lqType == '判断题'){
							lqList[i].myAnsSingleIndex = -1;
						}else if(lqList[i].lqType == '多选题'){
							lqList[i].multiOptIndexArr = [];
							for(var j=0;j<lqList[i].answerOptionArray.length;j++){
								var tmpObj = {
									selFlag:false
								};
								lqList[i].multiOptIndexArr.push(tmpObj)
							}
						}else if(lqList[i].lqType == '填空选择题'){
							lqList[i].tkOptIndexArr = [];
							for(var j=0;j<lqList[i].answerNum;j++){
								var tmpObj = {
									tkIndex:-1,
									value:''
								};
								lqList[i].tkOptIndexArr.push(tmpObj);
							}
						}
					}
					uni.setStorageSync('studyQueList',lqList);
				}).catch(err=>{
					console.log(err)
				});
			},
			goStepStudy(){
				var field = { studyLogId:this.studyLogId,nextLoreIdArray:this.nextLoreIdArray,loreTaskName:this.loreTaskName };
				uni.setStorageSync('stepField',field);
				uni.navigateTo({
					url:'/pages/subIndex/stepStudy/stepStudy?loreName=' + this.loreName + '&currSubId=' + this.currSubId + '&loreId=' + this.loreId + '&currentLoreId=' + this.currentLoreId
				})
			},
			backUp(){
				uni.navigateBack({delta:1})
			}
		}
	}
</script>

<style lang="scss">
	.studyWrap{
		position: absolute;
		left: 0;
		right: 0;
		@include respTo(phone){
			top: calc(110rpx + var(--status-bar-height));
		}
		@include respTo(pad){
			top: calc(90rpx + var(--status-bar-height));
		}
		bottom: 0rpx;
	}
	page{
		background: $pss-bg-primary;
	}
</style>
